package com.gitee.ykr.lightweight.rpc.util;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * 反射工具类
 * @author YKR
 * @Describe
 * @date 2021/8/23
 */
public class ReflectUtils {
    public static Object invoke(String clzName, String method, Object... args) throws ClassNotFoundException,
            NoSuchMethodException, IllegalAccessException, InstantiationException, InvocationTargetException {
        //通过类的名字获取字节码对象
        Class clz = Class.forName( clzName );
        //根据方法名获取方法
        Method method1 = clz.getMethod( method );
        //执行指定方法
        return method1.invoke( clz.newInstance(), args );
    }
}
